<?php

/**
* @Author:  	Daniel Dinh
* @Email:   	webdevelopmentvn@gmail.com
* @Link: 		http://www.joomsoft.net
* @Version: 	1.0
* @copyright:	Joomsoft.net
* @license:		Commercial
*/

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.controllerform');

class JSNPluginControllerJsnfield extends JControllerForm
{
	/**
	 * @var    string  The prefix to use with controller messages.
	 * @since  1.6
	 */
	protected $text_prefix = 'COM_JSNPLUGIN_JSNFIELD';

	/**
	 * Method override to check if you can add a new record.
	 *
	 * @param   array  $data  An array of input data.
	 *
	 * @return  boolean
	 *
	 * @since   1.6
	 */
	
	 
	protected function allowAdd($data = array())
	{
		// Initialise variables.
		$user		= JFactory::getUser();
		if ($allow === null)
		{
			// In the absence of better information, revert to the component permissions.
			return parent::allowAdd($data);
		}
		else
		{
			return $allow;
		}
	}

	
	function save()
	{
		$fdata = $this->getModel('field_data');
		$dataform = $_POST['jform'];
		$fopt = $_POST['fopt'];
		$data['id'] = $_POST['datafieldid'];
		$data['id_plugin'] = $dataform['id_plugin'];
		$data['id_field'] = $dataform['id'];
		$fopt['name'] = $dataform['title'];
		$fopt['type'] = $dataform['fieldtype'];
		$fopt['options'] = $dataform['options'];
		$data['data'] = json_encode($fopt);
		$fdata->save($data);
		parent::save();
	}

}
